<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title></title>

    <link rel="stylesheet" th:href="@{res/css/amazeui.min.css}">
    <link rel="stylesheet" th:href="@{res/css/admin.css}">
    <link rel="stylesheet" th:href="@{res/layui/css/layui.css}">
    <script th:src="@{js/jquery-1.11.3.min.js}"></script>
    <script th:src="@{myplugs/js/plugs.js}"></script>
</head>

<body>

<div class="admin-content-body">
    <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">用户管理</strong><small></small></div>
    </div>

    <hr>

    <div class="am-g" style="margin-top: 5px;">
        <div class="am-u-sm-12">

            <form class="am-form">
                <table class="am-table am-table-striped am-table-hover table-main">
                    <thead>
                    <tr>
                        <th class="table-id">
                            序号
                        </th>

                        <th>
                            用户名
                        </th>

                        <th>
                            用户类型
                        </th>
                        <th>
                            邮箱
                        </th>
                        <th>
                            手机
                        </th>
                        <th class="table-set">
                            操作
                        </th>

                    </tr>
                    </thead>
                    <tbody id="userTable">

                    </tbody>
                </table>
                <div class="am-cf" id="bottom_number"> </div>
            </form>
        </div>
    </div>
</div>

<script>
    //从url得到uid
    var result=new Object();
    result=getParameter();
    var uid=result["uid"];

    $(function() {
        var $tbody = $("#userTable");
        $.ajax({
            type:"post",
            url:"/user/getUserAllNotAdmin",
            data:{uid:uid},
            dataType:'json',
            success:function(data){
                //console.log(data);
                var newHtml='';
                for(var i=0;i<data.length;i++){
                    newHtml+='<tr>';
                    newHtml+='<td><span>' + (i+1) +'</span></td>';
                    newHtml+='<td> <a href="javascript:void(0)">' + data[i].name + '</a> </td>';
                    if(data[i].accountType == "1")
                    newHtml+='<td> <a href="javascript:void(0)"> 品牌商</a> </td>';
                    else if(data[i].accountType == "2")
                        newHtml+='<td> <a href="javascript:void(0)"> 借卖方</a> </td>';
                    else
                        newHtml+='<td> <a href="javascript:void(0)"> 管理员</a> </td>';
                    newHtml+='<td> <a href="javascript:void(0)">' + data[i].email + '</a> </td>';
                    newHtml+='<td> <a href="javascript:void(0)">' + data[i].phone + '</a> </td>';
                    newHtml+='<td>';
                    newHtml+='<div class="am-btn-toolbar">';
                    newHtml+='<div class="am-btn-group am-btn-group-xs">';
                    newHtml+='<button type="button" class="am-btn am-btn-default" onclick="delUser(\'删除用户\','+ data[i].id + ')">';
                    newHtml+='<span class="am-icon-trash-o"></span> 删除</button>';
                    newHtml+='</div>';
                    newHtml+='</div>';
                    newHtml+='</td>';
                    newHtml+=' </tr>';
                }
                $tbody.html(newHtml);
                $("#bottom_number").append("共" + data.length+ "条记录");
            },
            error:function(result){
                alert("后台出错!");
            }
        })
    });


    //添加编辑弹出层
    function delUser(title,id){
        $.jq_Panel({
            title: title,
            iframeWidth: 350,
            iframeHeight: 100,
            url: "/deleteUser?id=" + id
        });
    }

    //解析url传值
    function getParameter() {
        var url = location.search;//获取url?后面的内容
        var result = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                result[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
            }
        }
        return result;
    }
</script>
</body>
</html>